/**
 * 软件著作权：
 *
 * 系统名称：  云序列
 *
 * 文件名称：  DomainRestController.java
 *
 * 功能描述：  域名 rest controller
 * 
 * 版本历史：
 * 
 * 2015-10-11   1.0.0版 （龙色波）（创建文件）
 */
package com.dfhc.pub.rest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.dfhc.ISystemConstant;
import com.dfhc.base.domain.service.DomainService;
import com.dfhc.client.vo.RequestNextValueVo;
import com.dfhc.client.vo.ResponseNextValueVo;
import com.dfhc.pub.ISequenceConstants;
import com.dfhc.pub.service.SequenceService;

/**
 * list                 GET     /api/domain
 * get                  GET     /api/domain/{id}
 * insert action        POST    /api/domain
 * update action        PUT     /api/domain/{id}
 * delete action        DELETE  /api/domain/{id}
 * delete multi action  POST    /api/domain/delete
 * batch insert update  POST    /api/domain/batch
 */

/**
 * 序列rest controller
 * 
 * @author 龙色波
 * @see 参见的类
 */
@Controller
@RequestMapping(value = "/api/sequence")
public class SequenceRestController implements ISequenceConstants {

    @Autowired
    private SequenceService sequenceService;
 
    /**
     * 获取序列一个或多个序列值
     * @param vo
     * @return
     */
    @RequestMapping(value = "/getNextValue", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResponseNextValueVo getNextValue(HttpServletRequest request,HttpServletResponse response) {
       String requestVoJson;
       //请求vo json串
       requestVoJson = request.getParameter(ISystemConstant.PARAM_REQUESTJSON);
       //将	请求vo json反序列化为RequestNextValueVo
       RequestNextValueVo requestVo = JSON.parseObject(requestVoJson, RequestNextValueVo.class);
       ResponseNextValueVo responseNextValueVo = sequenceService.doGetNewNextSequenceValue(requestVo.getNum(), requestVo.getDomainName(), requestVo.getSequenceName(), requestVo.getParameters());
       return responseNextValueVo;
    }
    
}
